package com.easondongh.blog.controller;

import com.easondongh.blog.enums.ResultEnum;
import com.easondongh.blog.utils.Result;
import com.easondongh.blog.utils.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 * @author EasonDongH
 * @date 2020/3/31 16:11
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 图片上传
     * @param file
     * @return
     */
    @RequestMapping(value="/uploadImage", method = RequestMethod.POST)
    public Result<String> uploadImage(MultipartFile file) {
        String url = uploadService.uploadImage(file);
        return new Result<>( ResultEnum.UPLOAD_IMAGE_SUCCESS, url);
    }
}
